package com.example.dianproject.controller;

import com.example.dianproject.entity.ElectricityPrice;
import com.example.dianproject.service.ElectricityPriceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/electricity-price")
public class ElectricityPriceController {
    
    @Autowired
    private ElectricityPriceService electricityPriceService;
    
    @GetMapping("/current")
    public ResponseEntity<Map<String, BigDecimal>> getCurrentPrice() {
        BigDecimal residential = electricityPriceService.getCurrentResidentialPrice();
        BigDecimal commercial = electricityPriceService.getCurrentCommercialPrice();
        
        Map<String, BigDecimal> result = new HashMap<>();
        result.put("residentialPrice", residential);
        result.put("commercialPrice", commercial);
        
        return ResponseEntity.ok(result);
    }
    
    @PostMapping
    public ResponseEntity<ElectricityPrice> addPrice(@RequestBody ElectricityPrice price) {
        ElectricityPrice saved = electricityPriceService.savePrice(price);
        return ResponseEntity.ok(saved);
    }
    
    @GetMapping("/history")
    public ResponseEntity<List<ElectricityPrice>> getPriceHistory() {
        List<ElectricityPrice> history = electricityPriceService.getHistory();
        return ResponseEntity.ok(history);
    }
} 